package com.itheima.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * @description:
 * @author: 付益民
 * @create: 2020-09-25-21:06
 */
@Component
@Aspect
public class MyAspect {
    @Pointcut("execution(* com.itheima.service.*Service.find*(..))")

    public void pt(){}

    @Around("pt()")
    public Object runTimemonitor(ProceedingJoinPoint pj) throws Throwable {
        Signature signature = pj.getSignature();
        String typeName = signature.getDeclaringTypeName();
        String name = signature.getName();
        long l1 = System.currentTimeMillis();
        Object ret = pj.proceed(pj.getArgs());
        long l2 = System.currentTimeMillis();
        System.out.println(typeName+"中"+name+"运行时长"+(l2-l1)+"ms");
        return  ret;
    }
}
